# {{ ansible_managed }}

# The following lines are desirable for IPv4 capable hosts
{% if hosts_hostname_loopback %}
127.0.0.1 {{ inventory_hostname | lower }} {{ inventory_hostname_short | lower }}
{% endif %}
127.0.0.1 localhost.localdomain localhost
127.0.0.1 localhost4.localdomain4 localhost4
{{ hosts_ipv4_address }} {{ inventory_hostname | lower }} {{ inventory_hostname_short | lower }}
{% if ansible_lo.ipv6 is defined and hosts_ipv6 %}

# The following lines are desirable for IPv6 capable hosts
{% if hosts_hostname_loopback %}
::1 {{ inventory_hostname | lower }} {{ inventory_hostname_short | lower }}
{% endif %}
::1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
::1 ip6-localhost ip6-loopback
{% if hostvars[inventory_hostname]['ansible_default_ipv6']['address'] is defined %}
{{ hostvars[inventory_hostname]['ansible_default_ipv6']['address'] }} {{ inventory_hostname | lower }} {{ inventory_hostname_short | lower }}
{% endif %}
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
{% endif %}

{% if hosts_inventory_to_hosts %}
# The following lines are generated from the ansible inventory
{% for host in groups['all'] %}
{% if hostvars[host]['ansible_interfaces'] is defined %}
{% for interface in hostvars[host]['ansible_interfaces'] %}
{% if interface | regex_search('^((?!' +  hosts_exludes_interfaces | join('|') + '*).)*$')  %}
{% if hostvars[host]['ansible_' + interface]['ipv4']['address'] | ansible.netcommon.ipaddr('private') and hosts_all_private %}
{{ hostvars[host]['ansible_' + interface]['ipv4']['address'] }} {{ hostvars[host]['ansible_hostname'] }} {{ host }}{{ " " if hostvars[host]['hosts_aliases'] is defined }}{% if hostvars[host]['hosts_aliases'] is defined %}{% for alias in hostvars[host]['hosts_aliases'] %}{{ alias }}{{ " " if not loop.last }}{% endfor %}{% endif %}{{ '\n' -}}
{% elif hostvars[host]['ansible_' + interface]['ipv4']['address'] | ansible.netcommon.ipaddr('public') and hosts_all_public %}
{{ hostvars[host]['ansible_' + interface]['ipv4']['address'] }} {{ hostvars[host]['ansible_hostname'] }} {{ host }}{{ " " if hostvars[host]['hosts_aliases'] is defined }}{% if hostvars[host]['hosts_aliases'] is defined %}{% for alias in hostvars[host]['hosts_aliases'] %}{{ alias }}{{ " " if not loop.last }}{% endfor %}{% endif %}{{ '\n' -}}
{% elif not hosts_all_private and not hosts_all_public %}
{{ hostvars[host]['ansible_default_ipv4']['address'] }} {{ hostvars[host]['ansible_hostname'] }} {{ host }}{{ " " if hostvars[host]['hosts_aliases'] is defined }}{% if hostvars[host]['hosts_aliases'] is defined %}{% for alias in hostvars[host]['hosts_aliases'] %}{{ alias }}{{ " " if not loop.last }}{% endfor %}{% endif %}{{ '\n' -}}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% if hosts_ipv6 %}
{% for host in groups['all'] %}
{% if hostvars[host]['ansible_interfaces'] is defined %}
{% for interface in hostvars[host]['ansible_interfaces'] %}
{% if interface | regex_search('^((?!' +  hosts_exludes_interfaces | join('|') + '*).)*$')  %}
{% if hostvars[host]['ansible_' + interface]['ipv6']['address'] | ansible.netcommon.ipaddr('private') and hosts_all_private %}
{{ hostvars[host]['ansible_' + interface]['ipv6']['address'] }} {{ hostvars[host]['ansible_hostname'] }} {{ host }} {% set aliases=[] %}{% if hostvars[host]['hosts_aliases'] is defined %}{% for alias in hostvars[host]['hosts_aliases'] %}{% if alias != hostvars[host]['internel_ansible_host'] %}{{ aliases.append(alias) }}{% endif %}{% endfor %}{% endif %}
{% elif hostvars[host]['ansible_' + interface]['ipv6']['address'] | ansible.netcommon.ipaddr('public') and hosts_all_public %}
{{ hostvars[host]['ansible_' + interface]['ipv6']['address'] }} {{ hostvars[host]['ansible_hostname'] }} {{ host }} {% set aliases=[] %}{% if hostvars[host]['hosts_aliases'] is defined %}{% for alias in hostvars[host]['hosts_aliases'] %}{% if alias != hostvars[host]['internel_ansible_host'] %}{{ aliases.append(alias) }}{% endif %}{% endfor %}{% endif %}
{% elif not hosts_all_private and not hosts_all_public %}
{{ hostvars[host]['ansible_default_ipv6']['address'] }} {{ hostvars[host]['ansible_hostname'] }} {{ host }} {% set aliases=[] %}{% if hostvars[host]['hosts_aliases'] is defined %}{% for alias in hostvars[host]['hosts_aliases'] %}{% if alias != hostvars[host]['internel_ansible_host'] %}{{ aliases.append(alias) }}{% endif %}{% endfor %}{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
{% endif %}

{% if hosts_dns_hostname is defined %}
# The following lines are generated by ansible with hosts_dns_hostname variable
{% for item in hosts_dns_hostname %}
{{ item.address }} {{ item.hostname }}{% if item.aliases is defined %}{% for alias in item.aliases %} {{ alias }}{% endfor %}{% endif %}
{% if not loop.last %}

{% endif %}
{% endfor %}
{% endif %}
